<!-- Author: Edwin -->
<template>
  <el-switch :disabled="!$hasPermission('sys:user:update')"
             v-model='$data.data.teamsMessageSwitch'
             v-loading="loading"
             @change="changeMessageStatus"></el-switch>
</template>

<script>
import { BridgeUser } from './BridgeComponentForUser'

export default {
  data () {
    return {
      loading: false
    }
  },
  methods: {
    changeMessageStatus (e) {
      this.loading = true
      const params = {
        userId: this.$data.data.id,
        keyword: 'teams.message.switch',
        value: e
      }
      this.$interface.system.postSettingUserApi(params)
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg)
          }
          BridgeUser.$emit('updateUserList')
          return this.$message.success(res.msg)
        }).catch(() => { }).finally(() => {
          this.loading = false
        })
    }
  }
}
</script>
